package tcl.hujb.testitem;

import android.graphics.Camera;
import android.graphics.Matrix;
import android.util.Log;
import android.view.animation.Animation;
import android.view.animation.LinearInterpolator;
import android.view.animation.Transformation;

public class PhotoSelectedAnimation extends Animation {
	private int mCenterX;
	private int mCenterY;
	private Camera camera = new Camera();
	private String TAG = "PhotoSelectedAnimation";

	@Override
	public void initialize(int width, int height, int parentWidth,int parentHeight) {
		super.initialize(width, height, parentWidth, parentHeight);
		Log.d(TAG , "initialize");
		mCenterX = width / 2;
		mCenterY = height / 2;
		 setDuration(400);//设置动画时间延时
//		setDuration(10);// 设置动画时间延时
//		setFillAfter(true);
		setFillAfter(true);
		setInterpolator(new LinearInterpolator());
		setFillBefore(true);
		// setInterpolator(new AccelerateInterpolator());
		// setInterpolator(new AccelerateDecelerateInterpolator());
	}

	@Override
	protected void applyTransformation(float interpolatdTime, Transformation t) {
		final Matrix matrix = t.getMatrix();
		Log.d(TAG , "applyTransformation");
		camera.save();
		camera.translate(-0.0f, 0.0f, -100.0f);
		// camera.rotateX(-8*interpolatdTime);
		camera.getMatrix(matrix);
		camera.restore();
		matrix.preTranslate(-mCenterX, -mCenterY);
		matrix.postTranslate(mCenterX, mCenterY);
	}
}
